/*
 * 
 * 
 * 
 */
package com.hboxs.asl.entity;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.hboxs.asl.util.DateUtils;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * Entity - 财务记录
 */
@Entity
@Table(name = "xx_financialRecord")
@SequenceGenerator(name = "sequenceGenerator", sequenceName = "xx_xx_financial_record")
public class FinancialRecord extends OrderEntity {

    private static final long serialVersionUID = -6109590090908743215L;

    /**
     * 金额
     */
    private BigDecimal amount;

    /**
     * 订单编号
     */
    private String sn;

    /**
     * 用户
     */
    private Member member;

    /**
     * 来源
     */
    public enum Sourse {

        // 易问易答
        question,

        // 视频
        live,

        //直播送礼
        liveGifts;

        private static Map<String, FinancialRecord.Sourse> map = new HashMap<>();

        static {
            map.put("易问易答", question);
            map.put("视频", live);
            map.put("直播送礼", liveGifts);
        }

        @JsonCreator
        public static FinancialRecord.Sourse forValue(String value) {
            return map.get(value);
        }

        @JsonValue
        public String toValue() {
            for (Map.Entry<String, FinancialRecord.Sourse> entry : map.entrySet()) {
                if (entry.getValue() == this) {
                    return entry.getKey();
                }
            }
            return "";
        }
    }

    private Sourse sourse;

    /**
     * 类型
     */
    public enum Status {

        // 收入记录
        incomeRecord,

        // 支出记录
        expenditureRecord;

        private static Map<String, FinancialRecord.Status> map = new HashMap<>();

        static {
            map.put("收入记录", incomeRecord);
            map.put("支出记录", expenditureRecord);
        }

        @JsonCreator
        public static FinancialRecord.Status forValue(String value) {
            return map.get(value);
        }

        @JsonValue
        public String toValue() {
            for (Map.Entry<String, FinancialRecord.Status> entry : map.entrySet()) {
                if (entry.getValue() == this) {
                    return entry.getKey();
                }
            }
            return "";
        }
    }

    private Status status;

    /**
     * 标记
     */
    private String remark;

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public String getSn() {
        return sn;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    public Member getMember() {
        return member;
    }

    public void setMember(Member member) {
        this.member = member;
    }

    public Sourse getSourse() {
        return sourse;
    }

    public void setSourse(Sourse sourse) {
        this.sourse = sourse;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    @Transient
    public String getCreateDateF(){
        return DateUtils.dateToStr(super.getCreateDate());
    }


}